﻿using System;
using System.IO;

namespace mortal_ClipboardSharing_windows.utils
{
    public class Cache
    {
        private static FileStream GetFile()
        {
            FileStream fs;
            string path = "\\MortalShare";
            string appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            if (!Directory.Exists(appData + path))
            {
                Directory.CreateDirectory(appData + path);
            }
            if (File.Exists(appData + path + "\\mortalshare"))
            {
                fs = new FileStream(appData + path + "\\mortalshare", FileMode.Open);
            }
            else
            {
                fs = new FileStream(appData + path + "\\mortalshare", FileMode.OpenOrCreate);
            }
            return fs;
        }

        public static void SaveToken(string token)
        {
            //数据保存到磁盘中
            BinaryWriter bw = new BinaryWriter(GetFile());
            bw.Write(token);
        }

        public static string GetToken()
        {
            BinaryReader br = new BinaryReader(GetFile());
            return br.ReadString();
        }
    }
}
